package com.bang.study.controller;

import com.bang.study.common.Result;
import com.bang.study.common.ResultCode;
import com.bang.study.entity.Mail;
import com.bang.study.service.ITestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.Errors;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Autowired
    private ITestService testService;



    @PostMapping("send")
    public Result sendMail(@Validated Mail mail, Errors errors) {
        if (errors.hasErrors()) {
            String msg = errors.getFieldError().getDefaultMessage();
            return new Result().setCode(ResultCode.FAIL_PARAM).setMessage(msg);
        }

        return testService.send(mail);
    }
}
